package l_chain_of_responsibility.b_design_pattern;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wug on 2016/8/9 0009.
 */
public class SensitiveHandler implements Handler {
    @Override
    public void doFilter(Request request, Response response, FilterChain chain) {
        System.out.println("----------敏感词过滤 begin--------");
        String str = request.getRequestStr();
        List<String> sensitiveList = getSencitiveDict();
        for (String sensitive : sensitiveList) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < sensitive.length(); i++) {
                sb.append("*");
            }

            str = str.replace(sensitive, sb);
        }
        request.setRequestStr(str);
        response.setResponseStr(str);
        System.out.println("----------敏感词过滤 end--------");
    }

    private List<String> getSencitiveDict() {
        List<String> list = new ArrayList<>();
        list.add("AV女优");
        list.add("绿茶婊");
        list.add("日了狗");
        return list;
    }
}
